package vip.source.pattern.part01.base.enums;

import vip.source.pattern.part01.improve.service.ICommodity;
import vip.source.pattern.part01.improve.service.impl.CardCommodityService;
import vip.source.pattern.part01.improve.service.impl.CouponCommodityService;
import vip.source.pattern.part01.improve.service.impl.GoodsCommodityService;

public enum AwardTypeEnum {
    coupon(1, "优惠券", new CouponCommodityService()),
    goods(2, "实物商品", new GoodsCommodityService()),
    card(3, "兑换卡", new CardCommodityService());

    private Integer value;
    private String name;
    private ICommodity commodity;

    AwardTypeEnum(Integer value, String name, ICommodity commodity) {
        this.value = value;
        this.name = name;
        this.commodity = commodity;
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public ICommodity getCommodity() {
        return commodity;
    }

    public static ICommodity getConcreteCommodity(Integer value) {
        for (AwardTypeEnum each : values()) {
            if (each.value.equals(value)) {
                return each.getCommodity();
            }
        }
        return null;
    }
}
